package IC.Types;

public class MethodType extends Type {
	
	final String Name;
	private final Type[] FormalTypes;
	private final Type returnType;
	
	//C'tor
	public MethodType(String Name, Type[] FormalTypes, Type returnType) {
		this.Name = Name;
		this.FormalTypes = FormalTypes;
		this.returnType = returnType;
	}
	
	@Override
	public boolean isSuitForArray() {
		return false;
	}

	@Override
	public String toString() {
		return "{" + getSignature(getReturnType(), getFormalTypes()) + "}";
	}

	@Override
	public boolean isArray() {
		return false;
	}

	@Override
	public boolean isClass() {
		return false;
	}

	@Override
	public boolean isMethod() {
		return true;
	}

	@Override
	public boolean isPrimitive() {
		return false;
	}
	
	public Type getReturnType() {
		return returnType;
	}

	public Type[] getFormalTypes() {
		return FormalTypes;
	}
	
	/**
	 * returns a string that represent a method signature
	 */
	public static String getSignature(Type returnType,Type[] FormalTypes) {
		String str;
		if (FormalTypes.length == 0) 
			str = "";
		else {
			str = FormalTypes[0].toString();
			for (int i = 1; i < FormalTypes.length; i++) 
				str += ", " + FormalTypes[i];
		}
		return str + " -> " + returnType;
	}

}
